<template>
  <div>
    <el-dialog
      :visible.sync="visible"
      title="审核"
      width="60%"
      :before-close="handleClose"
    >
      <el-form
        :model="dispatchForm"
        :rules="dispatchFormRules"
        ref="dispatchFormRef"
        label-width="110px"
      >
        <el-form-item label="审核结果" prop="result">
            <el-radio-group v-model="dispatchForm.result">
              <el-radio label="1" :key="1">审核通过</el-radio>
              <el-radio label="2" :key="2">审核不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审批意见" prop="opinion"
          :rules="
            dispatchForm.result == 2
              ? [{ required: true, message: '请输入不通过原因', trigger: 'blur' }]
              : []
          ">
            <el-input type="textarea" v-model="dispatchForm.opinion" placeholder="审核不通过时必填"></el-input>
          </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button
          class="theme-background-color"
          @click="saveDispatchInfo"
          :disabled="isDisabled"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {

  props: {
    examineHospitalLook: {
      type: Boolean,
      default: function () {
        return {}
      }
    },
    hospital_id: {
      type: Number,
      default: function () {
        return {}
      }
    }
  },
  data() {
    return {
      visible: false,
      products: [],
      providers: [],
      dispatchForm: {
        result: "1",
        opinion: "",
        id: ""
      },
      dispatchFormRules: {
        result: [{ required: true, message: '请选择', trigger: 'change' }]
      },
      isDisabled: false
    }
  },
  created() {},
  methods: {
    // 左上角关闭
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          this.$emit('update:examineHospitalLook', false)
          done()
        })
        .catch((_) => {})
    },
    // 取消按钮
    closeDialog() {
      this.$emit('update:examineHospitalLook', false)
    },
    // 保存按钮
    async saveDispatchInfo() {
      this.dispatchForm.id = this.hospital_id
      this.$refs.dispatchFormRef.validate(async (valid) => {
        if (!valid) return
        this.isDisabled = true
        const { data: res } = await this.$http.post(
          '/admin/Hospital/examineHospital',
          this.dispatchForm
        )
        this.isDisabled = false
        if (res.meta.status !== 200) {
          return this.$message.error(res.meta.msg)
        }
        this.$message.success('审核成功')
        this.visible = false
        this.$emit('update:examineHospitalLook', false)
        parent.location.reload()
      })
    }
  },
  watch: {
    examineHospitalLook() {
      this.visible = this.examineHospitalLook
    }
  }
}
</script>

<style lang="less" scoped>
.el-form {
  width: 80%;
  margin-left: 15px;
  .el-select {
    width: 100%;
  }
}
</style>
